<template>
	<view class="content">
		<view class="skiplist">
			<image class="imgbalk" src="https://mgpicp.meishukr.com/org/icon2/2023124zhimaxinyong.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import Base64 from 'base-64'
	export default {
		data() {
			return {
				masg: true,
				keyURL: '', // 获取的页面信息
				accessToken: "",
				unLink: "",
			}
		},
		onLoad() {
			// let pageUrl = window.location.href;
			// // let pageUrl =
			// // 	"http://mgpic.meishukr.com/H5pay/index.html?type=1&url=aHR0cHM6Ly94Y3hwLm1laXNodWtyLmNvbS9jYXNoaWVyL29yZGVyL2NyZWF0ZS8xNzMwMTg2MTk3NTQ2NzkwOTEy#/";
			// let paramArr = pageUrl.split('?')[1].split('&')[1].split('=')[1] //获取url中"?"符后的字串
			// if (paramArr.indexOf('#/') >= 0) {
			// 	paramArr = paramArr.split('#')[0]
			// }
			// this.keyURL = Base64.decode(paramArr) // 解析出来的base64码
			// alert('看看页面链接?', window.location.href)
			// if (this.keyURL) {
			// 	this.isWeiXinLogin();
			// 	// this.getAccessToken(); // 获取 accessToken
			// };
			// this.getAccessToken(); // 获取 accessToken

			// location.href = 'https://wxaurl.cn/fQIlalT5joi';

			// window.location.href = 'https://qr.alipay.com/bax09426jmila7rjbjty00d0';

		},

		methods: {
			//判断是否微信登陆
			isWeiXinLogin() {
				var ua = window.navigator.userAgent.toLowerCase()
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					alert('这是微信')
					location.href = 'http://mgpic.meishukr.com/H5pay/weixin/ceshi'
				} else {
					// return window.location.href = 'https://qr.alipay.com/bax09426jmila7rjbjty00d0'; // 其他码打开
					console.log('在支付宝中扫码')
					uni.request({
						url: `${this.keyURL}?payChannel=alipay_wap`,
						method: 'GET',
						dataType: 'json',
						header: {
							'Content-type': 'application/json',
						},
						success: (res) => {
							let doutbe = JSON.stringify(res.data)
							let butlist = JSON.parse(doutbe)
							window.location.href =
								`alipays://platformapi/startapp?saId=10000007&qrcode=${butlist.data.redirectUrl}`
						},
					})
				}
			},

			// 获取access_token接口
			getAccessToken() {
				const that = this;
				uni.request({
					url: 'https://mparent.meishukr.com/user/accessToken',
					success: function(res) {
						alert('84=' + res.data)
						that.generateUrlLink(res.data) // 获取URLLink码
						// that.getScheme(res.data); // 获取scheme码
						// if (res.statusCode == 200) {
						// 	// that.getScheme(res.data); // 获取scheme码
						// 	// that.generateUrlLink(res.data) // 获取URLLink码

						// } else {
						// 	console.log('没有获取到 access_token')
						// }
					},
					fail(err) {
						alert(err + '10');

					}
				})
			},

			// 获取URLLink码
			generateUrlLink(urlLink) {
				alert("获取urllink码的链接 ?? ");
				const that = this;
				let linkt = {
					path: 'pages/bookmark/index',
					query: "",
					is_expire: true,
					expire_type: 1,
					expire_interval: 30,
					env_version: 'trial',
				};

				uni.request({
					url: `dapi/wxa/generate_urllink?access_token=${urlLink}`,
					method: 'POST',
					data: linkt,
					success: function(res) {
						let callword = '';
						alert(res.code);

						if (res.statusCode == 200) {
							console.log('获取的小程序码', res);
							// alert(" 最终的小程序码 ", res.data.url_link);
							location.href = res.data.url_link;
						};

						// if (res.statusCode == 200) {
						// 	if (res.data.errcode == 0) {
						// 		// window.location.href = res.data.url_link;
						// 		that.unLink = res.data.url_link;
						// 	} else if (res.data.errcode == -1) {
						// 		callword = '系统繁忙，请稍候再试'
						// 	} else if (res.data.errcode == 40001) {
						// 		callword = 'token失效,请稍候再试'
						// 	} else if (res.data.errcode == 40002) {
						// 		callword = '暂无生成权限,请检查后重试'
						// 	} else if (res.data.errcode == 40013) {
						// 		callword = '生成权限被封禁'
						// 	} else if (res.data.errcode == 40165) {
						// 		callword = '参数path填写错误，更正后重试'
						// 	} else if (res.data.errcode == 44990) {
						// 		callword = '频率过快，超过100次/秒；降低调用频率'
						// 	} else if (res.data.errcode == 44993) {
						// 		callword = '单天生成URL Link数量超过上限50万'
						// 	} else {
						// 		return false
						// 	}
						// 	uni.showToast({
						// 		title: callword,
						// 		duration: 1000,
						// 		icon: 'none',
						// 	})
						// }
					},
				})
			},

			// 获取scheme码
			getScheme(scheme) {
				// env_version:  release(正式版)  trial(体验版) develop(开发版) - 只有是在外部网站打开网页时的设置才有效, 微信内部打开只能是正式版
				// 	"expire_time": new Date().getTime(),
				let adata = {
					jump_wxa: {
						path: '/pages/bookmark/index',
						query: '',
						env_version: 'trial',
					},
					is_expire: true,
					expire_type: 1,
					expire_interval: 1,
				}
				uni.request({
					url: `dapi/wxa/generatescheme?access_token=${scheme}`,
					method: 'POST',
					data: adata,
					success: function(ret) {
						if (ret.statusCode == 200) {
							let promptit = ''
							if (ret.data.errcode == 0) {
								window.location.href = ret.data.openlink
								alert('小程序*scheme码', ret.data.openlink)
								return false
							} else if (ret.data.errcode == 40002) {
								promptit = '暂无生成权限'
							} else if (ret.data.errcode == -1) {
								promptit = '系统繁忙，请稍候再试'
							} else if (ret.data.errcode == 40001) {
								promptit = 'access_token无效,更正后重试'
							} else if (ret.data.errcode == 40165) {
								promptit = '参数path填写错误，更正后重试'
							} else if (ret.data.errcode == 44990) {
								promptit = '频率过快，请稍后重试'
							} else if (ret.data.errcode == 40013) {
								promptit = '生成权限被封禁'
							} else {
								return false
							}
							uni.showToast({
								title: promptit,
								duration: 1000,
								icon: 'none',
							})
						}
					},
				})
			},
		},
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}

	.skiplist {
		width: 100%;
		height: 100vh;
		outline: 1px solid rebeccapurple;
		display: flex;
		justify-content: center;

	}

	.imgbalk {
		width: 414rpx;
		margin-top: 402rpx;
	}
</style>